package com.example.lzy.anzhuotest;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

public class Main2Activity extends AppCompatActivity {

    private CheckBox cb1 = null;
    private CheckBox cb2 = null;
    private CheckBox cb3 = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.checkbox_radiobutton);

        cb1 = (CheckBox) findViewById(R.id.bj_cb);
        cb2 = (CheckBox) findViewById(R.id.nc_cb);
        cb3 = (CheckBox) findViewById(R.id.sz_cb);

        cb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                toastStr(compoundButton);
            }
        });
        cb2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                toastStr(compoundButton);
            }
        });
        cb3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                toastStr(compoundButton);
            }
        });

    }
    private void toastStr(CompoundButton compoundButton) {

        String city = compoundButton.getText().toString();

        if (compoundButton.isChecked()){
            Toast.makeText(Main2Activity.this,"选中"+city, Toast.LENGTH_SHORT).show();
        }else {
            Toast.makeText(Main2Activity.this,"取消"+city, Toast.LENGTH_SHORT).show();
        }
    }
}
